//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    topList: [
      "宝贝", "详情"
    ],
p:{},
topIndex: 0,
  },

  switchTopTab: function (e) {
    var topIndex = parseInt(e.currentTarget.dataset.index);
    console.log("当前点击--->", this.data.topList[topIndex])
    this.setData({
      topIndex: topIndex
    })
  },
  addshopcar:function(){
var proarray=[]
var proobj={
  productId: this.data.p.id,
  price: this.data.p.prices.sale,
  img: this.data.p.imgs[0].href,
  title: this.data.p.title,
  specs : this.data.p.specs
}
    var repro = wx.getStorageSync('shop_pro')
    if (wx.getStorageSync('shop_pro')==''){
      repro=[]
    }
    var havesame=false;
    for (let item of repro) {
      if (proobj.productId == item.proobj.productId){
        item.pronum+=1
        havesame=true
        console.log('重复商品')
      }
    }
    if (havesame==false){
      var pronum = 1
      var shop_pro = {
        proobj: proobj,
        pronum: pronum,
        status: true
      }
      repro.push(shop_pro)
    }
    console.log(repro)
    wx.setStorage({
      key:'shop_pro',
      data: repro
    })
    wx.showToast({
      title: '添加成功',
      duration: 1000
    })
    app.gettotnum();
  },
  onLoad: function (options) {
    console.log(options)
    app.req("get", "/api/products/details?product_id=" + options.product_id, {}, function (res) {
        this.setData({
          p:res.data.data.content
        })
        wx.setNavigationBarTitle({
          title: res.data.data.content.title
        })
    }.bind(this))
  },
  onShareAppMessage: function () {
    return {
      title: '十里芳菲',
      path: 'pages/route2/index/index'
    }
  },
  onShow(){
    app.userLogin()
  }

})


